﻿using RsCms.Core;
using Rswl.Common.Core;

namespace RsCms.Application.Stat
{
    public class StatAppService : IStatAppService
    {
        IUserRepository userRepository;
        IPostsRepository postsRepository;
        public StatAppService(IUserRepository userRepository,IPostsRepository postsRepository)
        {
            this.userRepository = userRepository;
            this.postsRepository = postsRepository;
        }
        public async Task<StatDto> GetStatAsync()
        {
            StatDto stat = new StatDto();
            stat.MemberCount=await userRepository.Select.CountAsync();
            stat.PublishCount = await postsRepository.PostStore.Select.Where(x => x.Status == "published"&&x.Type=="post").CountAsync();
            stat.ScheduleCount = await postsRepository.PostStore.Select.Where(x => x.Status == "scheduled"&&x.Type=="post").CountAsync();
            stat.DarftCount = await postsRepository.PostStore.Select.Where(x => x.Status == "draft"&&x.Type == "post").CountAsync();

            return stat;
        }
    }
}
